﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using NathansMapInfoProjects.WindowManager.ViewModels;

namespace NathansMapInfoProjects.WindowManager.Views
{
    /// <summary>
    /// Interaction logic for OpenWindowsView.xaml
    /// </summary>
    public partial class OpenWindowsView : UserControl
    {
        public OpenWindowsView()
        {
            InitializeComponent();
        }

        private void TreeView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.F2)
                SetCurrentItemInEditMode(true);
        }

        private void SetCurrentItemInEditMode(bool EditMode)
        {
            // Make sure that the SelectedItem is actually a TreeViewItem
            // and not null or something else
            if (this.windowtreeview.SelectedItem is WindowViewModel)
            {
                WindowViewModel tvi = this.windowtreeview.SelectedItem as WindowViewModel;

                if (tvi != null)
                    tvi.SwitchToEditingMode.Execute(null);
            }
        }

        private void TreeViewItem_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem item = sender as TreeViewItem;
            if (item != null)
            {
                item.Focus();
                e.Handled = true;
            }
        }
    }
}
